import type { LoginResult, ThirdShortLoginParams } from '@/types/userInfo'
import { http } from '@/utils/http'

type LoginWxMinParams = {
  code: string
  encryptedData?: string
  iv?: string
}

type LoginMobileParams = {
  mobile: string
  code: string
}
/**
 * 小程序登录
 * @param data 请求参数
 */
export const postLoginWxMinAPI = (data: LoginWxMinParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login/wxMin',
    data,
  })
}

/**
 * 手机号登录
 * @param data  LoginMobileParams
 */
export const postLoginMobileAPI = (data: LoginMobileParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/api/user/mobileLogin',
    data,
  })
}

/**
 * 无code 手机号登录
 */
export const postLoginMobileNoCodeAPI = (data: { mobile: string }) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/api/user/mobileLoginNoCode',
    data,
  })
}

type LoginParams = {
  account: string
  password: string
}
/**
 * 传统登录-用户名+密码
 * @param data 请求参数
 */
export const postLoginAPI = (data: LoginParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/login',
    data,
  })
}

/** 第三方登录 */
export const postThirdShortLoginAPI = (params: ThirdShortLoginParams) => {
  return http<LoginResult>({
    method: 'POST',
    url: '/api/user/thirdShortLogin',
    data: params,
  })
}
